<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/3/17
 * Time: 20:55
 */
include 'conn.php';
//topLat:topLat,bottomLat:bottomLat,leftLng:leftLng,rightLng:rightLng
if($_POST['url']=='loadChange')
{
    $topLat=(float)$_POST['topLat'];
    $bottomLat=(float)$_POST['bottomLat'];
    $leftLng=(float)$_POST['leftLng'];
    $rightLng=(float)$_POST['rightLng'];
    $sql="SELECT C.type,C.lengthSize,C.width,C.color,M.number,M.lng,M.lat,M.scole FROM targetInfo as M JOIN typetable
 as C on (C.type=M.thetype) AND (M.lat<'$topLat')AND (M.lng>'$bottomLat') AND (M.lng<'$rightLng') AND M.lng>'$leftLng'";
    $result=$conn->query($sql);
    /*$sql='SELECT C.type,C.lengthSize,C.width,C.color,M.number,M.lng,M.lat,M.scole FROM targetInfo as M JOIN typetable as C on C.type=M.thetype';
    $result=$conn->query($sql);
    $css=$result->fetch_all();*/
    $css=$result->fetch_all();
    if(!$css)
    {
        echo "";
    }else{
        echo json_encode($css);
    }
}
elseif($_POST['url']=='saveChange')
{
    var_dump($_POST);
    $thetype=(int)$_POST['thetype'];
    $lng=(double)$_POST['lng'];
    $lat=(double)$_POST['lat'];
    $scole=(int)$_POST['scole'];
    $isDel=(int)$_POST['isDel'];
    //$sql="INSERT INTO typetable(lengthSize,width,color) VALUES ('$length','$width','$color')";
    $sql="INSERT INTO targetinfo(thetype,lng,lat,scole,isDel) VALUES('$thetype','$lng','$lat','$scole','$isDel')";
    $result=$conn->query($sql);

}elseif($_POST['url']=="updateChange")
{
    //UPDATE Persons SET Age=36 WHERE FirstName='Peter' AND LastName='Griffin
    $number=(int)$_POST['number'];
    $sql="UPDATE targetinfo set isDel=1 WHERE number='{$number}'";
    $result=$conn->query($sql);
}elseif($_POST['url']=="updateScole")
{
    $number=(int)$_POST['number'];
    $scole=(int)$_POST['scole'];
    $sql="UPDATE targetinfo set scole='$scole' WHERE number='{$number}'";
    $result=$conn->query($sql);
}
elseif ($_POST['url']=='updateLocation')
{
    $number=(int)$_POST['number'];
    $lng=(double)$_POST['lng'];
    $lat=(double)$_POST['lat'];
    $sql="UPDATE targetinfo set lng='$lng',lat='$lat' WHERE number='{$number}'";
    $result=$conn->query($sql);
}
$conn->close();